package com.ant.storage.utils;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author hzd
 * @version 1.0
 * @date 2023/8/29 14:37
 */
public class commonUtil {

    private static Pattern p = Pattern.compile("^[-\\+]?[\\d]*$");

    /*
     * 判断是否为整数
     * @param str 传入的字符串
     * @return 是整数返回true,否则返回false
     */
    public static boolean isInteger(String str) {
        return p.matcher(str).matches();
    }


    public static String getYearMonthDays() {
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 获取当前年份
        int year = currentDate.getYear();
        // 获取当前月份
        int month = currentDate.getMonthValue();
        String monthStr = String.valueOf(month);
        if (month < 10) {
            monthStr = "0" + month;
        }
        // 获取当前日期
        int day = currentDate.getDayOfMonth();
        String dayStr = String.valueOf(day);
        if (day < 10) {
            dayStr = "0" + day;
        }
        String str =  year + "年" +monthStr + "月" + dayStr+"日";
        return str;
    }

    public static String getYearMonthDay() {
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 获取当前年份
        int year = currentDate.getYear();
        // 获取当前月份
        int month = currentDate.getMonthValue();
        String monthStr = String.valueOf(month);
        if (month < 10) {
            monthStr = "0" + month;
        }
        // 获取当前日期
        int day = currentDate.getDayOfMonth();
        String dayStr = String.valueOf(day);
        if (day < 10) {
            dayStr = "0" + day;
        }
        String str = year + "-" + monthStr + "-" + dayStr;
        return str;
    }

    public static String yearMonth() {
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 获取当前年份
        int year = currentDate.getYear();
        // 获取当前月份
        int month = currentDate.getMonthValue();
        String str = year + "" + month;
        return str;
    }

    public static Integer getYear() {
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 获取当前年份
        int year = currentDate.getYear();
        return year;
    }

    public static Integer getMonth() {
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 获取当前年份
        int month = currentDate.getMonthValue();
        return month;
    }
    /**
     * 字符串 转 ArrayList
     *
     * @param str
     * @param delimiter
     * @return
     */
    public static ArrayList stringToArrayListWithStream(String str, String delimiter) {
        return Arrays.stream(str.split(delimiter))
                .map(String::trim)
                .filter(s -> !s.isEmpty())
                .collect(Collectors.toCollection(ArrayList::new));
    }

    public static ArrayList stringToArrayListWithStreames(String str, String delimiter) {
        return new ArrayList<String>(Arrays.asList(str.split(delimiter)));
    }
}
